#pragma once
#include "LRUCache.h"
#include <mutex>
#include <memory>

//缓存管理类——单例模式
class CacheManager{
public:
    ~CacheManager();
    static CacheManager *getInstance(); //获取静态单例对象
    void initCache(size_t num, const string &filename); //从磁盘文件中读取缓存信息
    LRUCache &getCache(size_t idx); //获取某个缓存
    mutex &getMutex(size_t idx); //获取某个缓存的锁
    void updateCache(); //定时更新所有的缓存
    CacheManager(const CacheManager &) = delete;
    CacheManager &operator=(const CacheManager &) = delete;
private:
private:
    CacheManager();
    static CacheManager *_instance;
    vector<LRUCache> _cacheList; //用来与用户交互的缓存列表，缓存的数量与线程个数一致
    vector<LRUCache> _cacheUpdateList; //用来更新和缓存列表
    vector<mutex> _mutexList; //每个线程的LRU缓存的互斥锁
};

